package com.sboot.shiro.common.beans;

/**
 * 返回数据对象： <br/>
 * code:1-成功，0-失败，2-警告，3-提示 <br/>
 * msg：返回信息 <br/>
 * type：返回类型：SUCCESS-成功, FAIL-失败, WARNING-警告, TIPS-提示, OTHER-其他 <br/>
 * data:返回数据 <br/>
 */
public class ReturnData {

	private String code = "1";

	private String msg;

	private Type type = Type.SUCCESS;

	private Object data;

	public ReturnData() {
		super();
	}

	public ReturnData(String code, String msg, Type type, Object data) {
		super();
		this.code = code;
		this.msg = msg;
		this.type = type;
		this.data = data;
	}

	/**
	 * 返回成功
	 * @param msg
	 * @param data
	 * @return
	 */
	public static ReturnData SUCCESS(String msg, Object data) {
		return new ReturnData("1", msg, Type.SUCCESS, data);
	}
	
	/**
	 * 返回失败
	 * @param msg
	 * @param data
	 * @return
	 */
	public static ReturnData FAIL(String msg, Object data) {
		return new ReturnData("0", msg, Type.FAIL, data);
	}

	/**
	 * 返回警告信息
	 * @param msg
	 * @param data
	 * @return
	 */
	public static ReturnData WARNING(String msg, Object data) {
		return new ReturnData("2", msg, Type.WARNING, data);
	}
	
	/**
	 * 返回提示信息
	 * @param msg
	 * @param data
	 * @return
	 */
	public static ReturnData TIPS(String msg, Object data) {
		return new ReturnData("3", msg, Type.TIPS, data);
	}
	
	/**
	 * 返回其他信息
	 * @param code
	 * @param msg
	 * @param data
	 * @return
	 */
	public static ReturnData OTHER(String code, String msg, Object data) {
		return new ReturnData(code, msg, Type.OTHER, data);
	}
	
	public enum Type {
		/** 成功 */
		SUCCESS,
		/** 失败 */
		FAIL,
		/** 警告 */
		WARNING,
		/** 提示 */
		TIPS,
		/** 其他 */
		OTHER;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "ReturnData [code=" + code + ", msg=" + msg + ", type=" + type + ", data=" + data + "]";
	}

}
